
int  cpe_refresh_igd_wd_comwaninterfaceconfig(cwmp_t * cwmp, parameter_node_t * param_node, callback_register_func_t callback_reg)
{
    FUNCTION_TRACE();

    if(!param_node)
    {
        return FAULT_CODE_9002;
    }
    parameter_node_t * tmp_param, *tmp_node, *child_param;
    child_param = param_node->child;
    if(child_param)
    {
        for(tmp_param=child_param->next_sibling; tmp_param; )
        {
            cwmp_log_info("refresh WANConnectionDevice node, delete param %s\n", tmp_param->name);
            tmp_node = tmp_param->next_sibling;
            cwmp_model_delete_parameter(tmp_param);
            tmp_param = tmp_node;
        }
        child_param->next_sibling = NULL;

		cwmp_log_info("ready to get wan index");
        int wan_index = get_index_after_paramname(param_node, "WANDevice"); 

        cwmp_log_info("wan index is:%d", wan_index);
		
        parameter_node_t * wan1conn_param;
        cwmp_model_copy_parameter(param_node, &wan1conn_param, 1);
		
        if(wan_index == 2)
        {
             parameter_node_t * wan2conn_param;
             cwmp_model_copy_parameter(param_node, &wan2conn_param, 2);
        }

        cwmp_model_refresh_object(cwmp, param_node, 0, callback_reg); 
    }

    return FAULT_CODE_OK;
}

#include "softap_api.h"

int split_string(char * rule_str,char ge,char **array,int max)
{
	int i=0,j=0;
	char *cp = rule_str;	
	int is_ge=0;

	for(j=0;j<max;j++)
		array[j] = NULL;
	
	while(cp && *cp && i < max)  //::
	{
		array[i++] = cp;
		is_ge=0;
		while(*cp && *cp != ge)
		{
			cp++;		
		}
		//cp= strchr(cp, ge);
		if(*cp)
		{
			is_ge = 1;
			*cp++=0;
		}
	}
	//if((is_ge == 1) && (i < max))
	//	array[i++] = cp;
	return i;	
}

int cpe_get_imei(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    char tmp[64+1] = {0};

	cfg_get_item("imei", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

    return	FAULT_CODE_OK;
}

int cpe_get_imsi(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    char tmp[64+1] = {0};

	cfg_get_item("sim_imsi", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

    return	FAULT_CODE_OK;
}


int cpe_get_cell_id(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[32] = {0};

	cfg_get_item("cell_id", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_sinr(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[64] = {0};
	void *p[] = {crsmrsp};
	char *args[9];
	int i;
	char tmp[64] = {0};
	int len = 0;
	
	result = get_modem_info("AT+ZSINR\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,8);
	
		for(i = 0;i < 8;i++)
		{
			len += sprintf(tmp+len,"%s.%s,",args[i+0],args[i+1]);
			i++;
		}
	}
	tmp[len-1] = '\0';
	*value = pool_pstrdup(pool, tmp);
	return FAULT_CODE_OK;
}


int cpe_get_plmn(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[12] = {0};
	char tmp1[12] = {0};
	cfg_get_item("mcc", tmp, sizeof(tmp)-1);
	cfg_get_item("mnc", tmp1, sizeof(tmp1)-1);
	strcat(tmp,tmp1);
	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;

}


int cpe_get_tac_code(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[12] = {0};

	cfg_get_item("tac_code", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_down_rate(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[64] = {0};

	cfg_get_item("realtime_rx_thrpt", tmp, sizeof(tmp)-1);
	
	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_up_rate(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[64] = {0};

	cfg_get_item("realtime_tx_thrpt", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_band_list(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[64] = "1,3,5,7,8,20,38,40,41";

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}



int cpe_set_band_lock(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
    FUNCTION_TRACE();	
	char tmp[64] = {0};
	int result = -1;

	sprintf(tmp,"AT+ZLTELC=%s\r\n",value);
	result = get_modem_info(tmp, NULL, NULL);
	if(result == 0)
		system("reboot");

    return FAULT_CODE_OK;
}




int cpe_get_neighborhood_pci(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[1056] = {0};
	void *p[] = {crsmrsp};
	char *args[64];
	int start_lte = 4;
	int i,j;
	char tmp[64] = {0};
	int len = 0;
	for(j = 0 ; j < 15 ; j++){
	result = get_modem_info("AT+ZNCELLINFO?\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		j = 15;
		result = split_string(crsmrsp, ',', args,63);
		if((atoi(args[3]) > 0)&&(atoi(args[3]) < 8))
		{
			if(atoi(args[1]) > 0)
				start_lte += atoi(args[1])*7;//TD
			if(atoi(args[2]) > 0)
				start_lte += atoi(args[1])*8;//W

			for(i = 0;i < atoi(args[3]);i++)
			{
				len += sprintf(tmp+len,"%s,",args[start_lte+4+i*8]);
			}
		}
	}
	sleep(1);
	}
	tmp[len-1] = '\0';
	*value = pool_pstrdup(pool, tmp);
	//result = get_modem_info("AT+ZMESCIQ=2\r\n", "%s",  p);
	//cwmp_log_info("AT+ZMESCIQ=2");
    return FAULT_CODE_OK;
}

int cpe_get_neighborhood_rsrp(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[1056] = {0};
	void *p[] = {crsmrsp};
	char *args[64];
	int start_lte = 4;
	int i,j;
	char tmp[64] = {0};
	int len = 0;
	for(j = 0 ; j < 15 ; j++){
		result = get_modem_info("AT+ZNCELLINFO?\r\n", "%s", p);
		if(strlen(crsmrsp) > 0)
		{
			j = 15;
			result = split_string(crsmrsp, ',', args,63);
			if((atoi(args[3]) > 0)&&(atoi(args[3]) < 8))
			{
				if(atoi(args[1]) > 0)
					start_lte += atoi(args[1])*7;//TD
				if(atoi(args[2]) > 0)
					start_lte += atoi(args[1])*8;//W

				for(i = 0;i < atoi(args[3]);i++)
				{
					len += sprintf(tmp+len,"%s,",args[start_lte+5+i*8]);
				}
			}
		}
		sleep(1);
	}
	tmp[len-1] = '\0';
	*value = pool_pstrdup(pool, tmp);
	//result = get_modem_info("AT+ZMESCIQ=2\r\n", "%s",  p);
	//cwmp_log_info("AT+ZMESCIQ=2");
    return FAULT_CODE_OK;
}

int cpe_get_duplexing_mode(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = {0};

	cfg_get_item("sub_act", tmp, sizeof(tmp)-1);

	if(atoi(tmp))
		*value = pool_pstrdup(pool, "FDD");
	else
		*value = pool_pstrdup(pool, "TDD");

	return	FAULT_CODE_OK;
}

int cpe_get_max_dl_speed(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = "90M";

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_max_ul_speed(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = "45M";

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_operation_band(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[16] = {0};
	void *p[] = {crsmrsp};
	char *args[4];
	char tmp[16] = {0};

	result = get_modem_info("AT+ZBAND?\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,3);
		if(atoi(args[0]) == 3)
			sprintf(tmp,"%s",args[1]);
	}

	*value = pool_pstrdup(pool, tmp);
	
    return FAULT_CODE_OK;
}

int cpe_get_rsrq(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[32] = {0};
	void *p[] = {crsmrsp};
	char *args[7];
	char tmp[32] = {0};

	result = get_modem_info("AT+CESQ\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,6);
		sprintf(tmp,"%s",args[4]);
	}

	*value = pool_pstrdup(pool, tmp);
	
    return FAULT_CODE_OK;
}

int cpe_get_cqi(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[64] = {0};
	void *p[] = {crsmrsp};
	char *args[6];
	char tmp[32] = {0};

	result = get_modem_info("AT+ZEPCG=14,0\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,5);
		sprintf(tmp,"%s,%s",args[3],args[4]);
	}

	*value = pool_pstrdup(pool, tmp);
	
    return FAULT_CODE_OK;
}

int cpe_get_rank(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[128] = {0};
	void *p[] = {crsmrsp};
	char *args[16];
	char tmp[16] = {0};

	result = get_modem_info("AT+ZEMSCIQ=1\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,15);
		sprintf(tmp,"%s",args[13]);
	}

	*value = pool_pstrdup(pool, tmp);
	
    return FAULT_CODE_OK;
}

int cpe_get_dlearfcn(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
    FUNCTION_TRACE();	
	int result = -1;
	char crsmrsp[128] = {0};
	void *p[] = {crsmrsp};
	char *args[16];
	char tmp[16] = {0};

	result = get_modem_info("AT+ZEMSCIQ=1\r\n", "%s", p);
	if(strlen(crsmrsp) > 0)
	{
		result = split_string(crsmrsp, ',', args,15);
		sprintf(tmp,"%s",args[7]);
	}

	*value = pool_pstrdup(pool, tmp);
	
    return FAULT_CODE_OK;
}

